#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;

bool IsQueenConflict(int *queen, int row)
{
	for (int i = 0; i < row; i++)
	{
		if (
			(queen[i] == queen[row])
			|| (abs(i - row) == abs(queen[i] - queen[row]))
			)
		{
			return true;
		}
	}

	return false;
}

int main(void)
{
	int queen[8]{ 0 };

	int i = 0;
	int caseNum = 0;
	while (-1 != i)
	{
		for (; i < 8; )		//8个皇后
		{
			int j = queen[i] + 1;
			for (; j < 9; j++)		//皇后的位置1~9
			{
				queen[i] = j;

				if (!IsQueenConflict(queen, i))
				{
					break;
				}
			}
			if (j == 9)
			{
				memset(&queen[i], 0, sizeof(int) * (8 - i));
				i--;

				if (-1 == i)
				{
					break;
				}
			}
			else
			{
				i++;
			}
		}

		if (i == 8)
		{
			cout << caseNum++ << ": ";
			for_each(queen, queen + 8, [](int e) {cout << e << " "; });
			cout << "\n";
			i--;
		}
	}

	return 0;
}
